#include "CDrawView.h"

CDrawView::CDrawView(QWidget* parent)
{
    init_All();
    setViewSize(this->size());
    m_pView->setParent(parent);
}

CDrawView::~CDrawView()
{

}

void CDrawView::init_All()
{
    init_View();
}

void CDrawView::init_View()
{
    m_pScene = new QGraphicsScene();
    m_pScene->setItemIndexMethod(QGraphicsScene::NoIndex);
    m_pView = new QGraphicsView(dynamic_cast<QGraphicsScene*>(m_pScene));
    m_pView->setWindowFlags(Qt::FramelessWindowHint);
    m_pView->setAttribute(Qt::WA_TranslucentBackground);
    m_pView->setAutoFillBackground(true);
    m_pView->setStyleSheet("background-color:'#E0E0E0';border:0px");
    m_pView->setRenderHint(QPainter::Antialiasing);
    m_pView->setCacheMode(QGraphicsView::CacheBackground);
    m_pView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    m_pView->setDragMode(QGraphicsView::NoDrag);
    m_pView->horizontalScrollBar()->resize(0,0);
    m_pView->verticalScrollBar()->resize(0,0);
    m_pView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_pView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_pView->horizontalScrollBar()->hide();
    m_pView->verticalScrollBar()->hide();
}

void CDrawView::setViewSize(QSize size)
{
    m_pScene->setSceneRect(0,-20,size.width(),size.height());
    m_pView->resize(size);
}

void CDrawView::addItem(QGraphicsItem *item)
{
    m_pScene->addItem(item);
}
